package com.yxkj.syh.app.huarong.activities.home.return_cars;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.syh.app.basic.base.BaseResponse;
import com.syh.app.basic.base.view_model.BaseViewModel;
import com.syh.app.basic.utils.Tooast;
import com.syh.app.basic.utils.net.ApiObserver;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.yxkj.syh.app.huarong.bean.ReturnCar;
import com.yxkj.syh.app.huarong.bean.ReturnCarResponse;
import com.yxkj.syh.app.huarong.data_center.model.ReportModel;

import java.util.HashMap;
import java.util.Map;

/**
 * 创建者：SYH
 * 时间：2020/6/3 17:30
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class ReturnCarVM extends BaseViewModel<ActivityEvent> {

    public ReturnCarVM(@NonNull Application application) {
        super(application);
    }

    public ObservableField<String> ofFrom = new ObservableField<>();
    public ObservableField<String> ofTo = new ObservableField<>();
    public ObservableField<String> ofCreatTime = new ObservableField<>();
    public ObservableField<String> ofCarID = new ObservableField<>();

    public MutableLiveData<ReturnCar> mldReturnCar = new MutableLiveData<>();

    public void returnCarInfo(long id){
        ReportModel.getReportModel().returnCarInfo(id,mLifecycleProvider.bindToLifecycle(), new ApiObserver<ReturnCarResponse>() {
            @Override
            public void onSuccess(ReturnCarResponse carResponse) {
                ReturnCar returnCar = carResponse.getData();
                ofFrom.set(returnCar.getStartArea());
                ofTo.set(returnCar.getEndArea());
                ofCreatTime.set(returnCar.getCreateTime());
                ofCarID.set(returnCar.getCarNo());
                mldReturnCar.setValue(returnCar);

            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }

    /**
     * 预约
     */
    public void appointment(long id,String remark){

        Map<String,Object> pMap = new HashMap<>();
        pMap.put("id",id);
        pMap.put("remark",remark);

        ReportModel.getReportModel().appointment(pMap,mLifecycleProvider.bindToLifecycle(), new ApiObserver<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse response) {
                Tooast.success(response.getMessage());
                finish();
            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }



}
